package com.umeox.watch.motioncapture.ui

import android.content.Context
import android.content.Intent
import android.os.Bundle
import android.util.Log
import android.widget.Button
import androidx.appcompat.app.AppCompatActivity
import com.umeox.watch.motioncapture.R

class UnitSelectActivity : AppCompatActivity() {

    companion object {
        private const val TAG = "UnitSelectActivity"
        private const val INTENT_KEY_TYPE = "type"
        const val INTENT_KEY_UNIT = "unit"
        const val DAILY_ACTIONS_TYPE = "DailyActions"
        const val PRAYER_ACTIONS_TYPE = "PrayerActions"

        fun startUnitSelectActivity(context: Context, type: String) {
            context.startActivity(Intent(context, UnitSelectActivity::class.java).apply {
                putExtra(INTENT_KEY_TYPE, type)
            })
        }
    }

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_unit_select)

        val type = intent?.getStringExtra(INTENT_KEY_TYPE)

        findViewById<Button>(R.id.bt_unit_2).setOnClickListener {
            intoActionActivity(2,type)
        }

        findViewById<Button>(R.id.bt_unit_3).setOnClickListener {
            intoActionActivity(3,type)
        }

        findViewById<Button>(R.id.bt_unit_4).setOnClickListener {
            intoActionActivity(4,type)
        }

    }

    private fun intoActionActivity(unit: Int, type: String?) {
        if (DAILY_ACTIONS_TYPE == type) {
            startActivity(Intent(this, DailyActionsActivity::class.java).apply {
                putExtra(INTENT_KEY_UNIT, unit)
            })
            finish()
        } else if (PRAYER_ACTIONS_TYPE == type) {
            startActivity(Intent(this, PrayerActionsActivity::class.java).apply {
                putExtra(INTENT_KEY_UNIT, unit)
            })
            finish()
        } else {
            Log.d(TAG, "intoActionActivity: unknown")
        }
    }
}